package com.reactlibrary;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build.VERSION_CODES;

import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.socialize.PlatformConfig;

/**
 * Created by wangfei on 17/9/14.
 */

public class RNUMConfigure {

    public static void initUmeng(Context context, HashMap<String, String> params) {
        UMConfigure.init(context, params.get(ParamsConstans.UMENG_APP_KEY), params.get(ParamsConstans.UMENG_APP_CHANNEL), UMConfigure.DEVICE_TYPE_PHONE, "");
        initRN("react-native", "2.0");
        PlatformConfig.setWeixin(params.get(ParamsConstans.WX_APP_ID), params.get(ParamsConstans.WX_APP_SECERECT));
        PlatformConfig.setQQZone(params.get(ParamsConstans.QQ_APP_ID), params.get(ParamsConstans.QQ_APP_SECERECT));
    }

    @TargetApi(VERSION_CODES.KITKAT)
    private static void initRN(String v, String t) {
        Method method = null;
        try {
            Class<?> config = Class.forName("com.umeng.commonsdk.UMConfigure");
            method = config.getDeclaredMethod("setWraperType", String.class, String.class);
            method.setAccessible(true);
            method.invoke(null, v, t);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void onResume(Context context) {
        MobclickAgent.onResume(context);
    }

    public static void onPause(Context context) {
        MobclickAgent.onPause(context);
    }

}
